# Master1 Project Change Summary

**Timestamp:** 2026-05-20 07:55 UTC

## Overview
This document records all actions performed on the `master1.vip` deployment to replace the **Garden Game** (لعبة حديقة الأزهار) with the **Card Duel Game** (لعبة بطاقات المبارزة) and related cache‑busting updates.

## Actions Timeline
| Time (UTC) | Action | Files Modified |
|------------|--------|----------------|
| 07:38 | Uploaded `Thanwy-duel.html` and set up SSH access. | — |
| 07:39 | Created `update_games.py` to edit `index-CCVDZxLI.js`. | `/var/www/master1.vip/dist/assets/index-CCVDZxLI.js` |
| 07:40 | Ran script – replaced games list, added `onClick`/`onKeyDown` guard for `coming_soon`. | Same JS file |
| 07:41 | Created `update_html.py` to inject `showSoonModal` helper and bump Service Worker version. | `/var/www/master1.vip/dist/index.html` |
| 07:41 | Executed HTML update – modal added, SW version bumped to `v7`. | Same HTML file |
| 07:41 | Created `update_sw.py` to bump cache name. | `/var/www/master1.vip/dist/sw.js` |
| 07:41 | Executed SW update – cache name changed to `v7`. |
| 07:57 | Created `replace_with_card_duel.py` to **remove the garden card completely** and set Card Duel as `g2`. Updated version to `v8` in HTML & SW. |
| 07:57 | Ran script – JS list updated, SW & HTML bumped to `v8`. |

## Issues Encountered & Fixes
1. **Shell quoting errors** while embedding JavaScript objects in the `ssh -c` command. **Fix:** Used a heredoc (`cat <<'EOF'`) on the remote side to avoid shell‑parsing of quotes.
2. **Cache stale** – browsers kept loading old assets. **Fix:** Bumped both the Service Worker registration query string (`?v=2026.05.20‑v8`) **and** the `CACHE_NAME` constant in `sw.js`.
3. **Modal not showing** when the garden card was still present. **Fix:** Added `window.showSoonModal()` function to `index.html` and rewrote the click handlers in the JS bundle to call it for `url === "coming_soon"`.
4. **Incorrect pattern match** for the original games list caused no replacement. **Fix:** Captured the exact current string from the bundle and replaced it with a new literal representation.

## Code Snippets (Key Changes)
### JS Bundle (`index-CCVDZxLI.js`)
```js
// Updated games array – garden removed, card duel promoted to g2
ig=[{id:"g1",title:"لعبة خريطة الكنز - شاطئ المعرفة",url:"https://q1q1f2ccxmv1-d.space.z.ai/",color:"linear-gradient(135deg, #06b6d4, #3b82f6)",icon:"🏖️",category:"game"},{id:"g2",title:"لعبة بطاقات المبارزة",url:"https://master1.vip/card-game",color:"linear-gradient(135deg, #7000FF, #FFD700)",icon:"🃏",category:"game"},{id:"g3",title:"لعبة برج المعرفة - البقاء للأقوى",url:"https://j1f0023dbuk0-d.space.z.ai/",color:"linear-gradient(135deg, #f59e0b, #ef4444)",icon:"🏰",category:"game"}]

// Guard against "coming_soon" links
onClick:()=>a.url==="coming_soon"?window.showSoonModal():s(a)
onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(a.url==="coming_soon"?window.showSoonModal():s(a))}
```
### HTML (`index.html`)
```html
<script>
  window.showSoonModal = function() {
    var modal = document.createElement('div');
    modal.id = 'soon-modal';
    modal.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.85);display:flex;align-items:center;justify-content:center;z-index:99999;font-family:sans-serif;color:#fff;direction:rtl;';
    modal.innerHTML = `<div style="background:#1e1b4b;padding:30px;border-radius:15px;text-align:center;position:relative;box-shadow:0 10px 25px rgba(0,0,0,0.5);border:2px solid #a855f7;width:90%;max-width:400px;">
      <button onclick="document.getElementById('soon-modal').remove()" style="position:absolute;top:10px;right:15px;background:none;border:none;color:#fff;font-size:28px;cursor:pointer;">&times;</button>
      <div style="font-size:50px;margin-bottom:15px;">🌸</div>
      <h2 style="margin-bottom:10px;font-size:22px;color:#a855f7;">لعبة حديقة الأزهار</h2>
      <p style="font-size:16px;color:#cbd5e1;margin-bottom:20px;">ستتوفر هذه اللعبة قريباً جداً! انتظرونا.</p>
      <button onclick="document.getElementById('soon-modal').remove()" style="background:#a855f7;color:#fff;border:none;padding:10px 25px;border-radius:8px;font-size:16px;font-weight:bold;cursor:pointer;">إغلاق</button>
    </div>`;
    document.body.appendChild(modal);
  };
</script>
<!-- Service Worker: unregister old, register new -->
return navigator.serviceWorker.register('/sw.js?v=2026.05.20-v8')
```
### Service Worker (`sw.js`)
```js
const CACHE_NAME = 'master1-cache-2026-05-20-v8';
```

## Pro Tips for Future Developers
- **Always bump a cache identifier** (query string or `CACHE_NAME`) after any static asset modification; otherwise users may see stale content.
- **Use heredocs for remote script creation** to avoid quoting issues, especially when the script contains JSON‑like structures or special characters.
- **Keep a backup** of the original files (`cp file file.bakX`) before overwriting – this makes rollback trivial.
- **Test click handlers locally** (e.g., with `node` or a temporary HTML page) before deploying to production to ensure the guard logic works.
- **Document changes** in a central markdown file (like this one) and keep it in version control; it speeds up onboarding and debugging.
- **Automate deployment**: wrap the series of `scp` + `ssh` commands into a single script or CI job to guarantee reproducibility.

---

*Document generated on the server via automated script.*
